home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_UDELxntp.idb / usr / freeware / src / xntp-3.4o-export / lib / prettydate.c.z / prettydate.c
C/C++ Source or Header  |  1998-01-21  |  914b  |  45 lines

  1. /*
  2.  * prettydate - convert a time stamp to something readable
  3.  */
  4. #include <stdio.h>
  5.  
  6. #include "ntp_fp.h"
  7. #include "ntp_unixtime.h"
  8. #include "lib_strbuf.h"
  9. #include "ntp_stdlib.h"
  10.  
  11. #ifdef NTP_POSIX_SOURCE
  12. #include <time.h>
  13. #endif
  14.  
  15. char *
  16. prettydate(ts)
  17.     l_fp *ts;
  18. {
  19.     char *bp;
  20.     struct tm *tm;
  21.     time_t sec;
  22.     u_long msec;
  23.     static char *months[] = {
  24.         "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  25.         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  26.     };
  27.     static char *days[] = {
  28.         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  29.     };
  30.  
  31.     LIB_GETBUF(bp);
  32.     
  33.     sec = ts->l_ui - JAN_1970;
  34.     msec = ts->l_uf / 4294967;    /* fract / (2 ** 32 / 1000) */
  35.  
  36.     tm = localtime(&sec);
  37.  
  38.     (void) sprintf(bp, "%08lx.%08lx  %s, %s %2d %4d %2d:%02d:%02d.%03lu",
  39.                (u_long)ts->l_ui, (u_long)ts->l_uf, days[tm->tm_wday],
  40.                months[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year,
  41.                tm->tm_hour,tm->tm_min, tm->tm_sec, msec);
  42.     
  43.     return bp;
  44. }
  45.